package com.video.netty.InChannelHandler;

import com.alibaba.fastjson.JSONObject;
import com.video.service.task.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 添加定时音乐的响应
 *
 * {"id":"addTaskResponse","response":"success","account":"admin","taskid":"145",
 * "duration":1800, "msgid": "xxxxxxxxxxxxx", "status":"succ"}
 */
@BaseChannelHandler.MsgHandler
public class WsAddTaskResponseChannelHandler extends BaseChannelHandler {

    @Autowired
    private ITaskService taskService;

    @Override
    protected String msgId() {
        return "addTaskResponse";
    }

    @Override
    protected void msgHandler(JSONObject json) throws Exception {
        String response = json.getString("response");
        if (response.equals("success")){
            //成功了
            String taskid = json.getString("taskid");
            int duration = json.getInteger("duration");

            //修改任务的持续时间
            taskService.updateTaskDuration(taskid, duration);
        }
    }
}
